<script type="text/javascript"><!--//--><![CDATA[//><!--

    var grid_reload = function() {
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };
    
    $(document).ready(function() {
       // Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			//singleSelect:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'pk_master', title : 'PK Master', width : 120, sortable:true },
				{ field : 'field1', title : 'Field 1', width : 250, sortable:true },
				{ field : 'field2', title : 'Field 2', width : 80, align:'center', formatter:function(val){ return formatDate(val); }, sortable:true },
				{ field : 'field3', title : 'Field 3', width : 80, align:'center', formatter:function(val){ return formatDate(val); }, sortable:true },
				{ field : 'field4', title : 'Field 4', width : 80, align:'right', formatter:function(val){ return formatNumeric(val,2); }, sortable:true },
				{ field : 'field5', title : 'Field 5', width : 80, align:'right', formatter:function(val){ return formatNumeric(val,5); }, sortable:true },
				{ field : 'province_name', title : 'Province Name', width : 200, align:'left', sortable:true },
				{ field : 'city_name', title : 'City Name', width : 200, align:'left', sortable:true }
			]]
		});
        
        // Set Action Button
        var buttons = [
                        // ----- >> Add Button
                        { label: 'Add', icon: 'add', onclick: function() {
							loadPage(gs_path + '/' + controller + '/create/');
                        }},
                        
                        // ----- >> Edit Button
					    { label: 'Edit', icon: 'edit', onclick: function() {
					        var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								loadPage(gs_path + '/' + controller + '/edit/?pk_master='+urlencode(oSel.pk_master));
					        } 
					    }},

					    // ----- >> Delete Button
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['pk_master']);
							} 
						}},
						
						// ----- >> Print Button
					    { label: 'Print', icon: 'print', onclick: function() {
							var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								window.open(gs_path+'/'+controller+'/cetak/?pk_master='+urlencode(oSel.pk_master), 'myWin', 'height=500,width=700,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
							}
					    }},
						
						// ----- >> Download Button
						{label: 'Download', icon:'excel', onclick: function() { 
							setLoading(true);
							$.ajax({
								type: 'POST', url: gs_path+'/'+controller+'/download/', cache: false, data: jQuery.param( $('#fm_search').serializeArray().concat({ name:'sessid', value:sessid })),
								success: function(data) { setLoading(false); if(data!=''){ alert(data); return false; } document.getElementById('if_download').src='<?php echo base_url(); ?>app/download/?file=<?php echo _SESSID; ?>.xls&filename=download_data.xls'; },
								error: function(xhr, ajaxOptions, thrownError) { setLoading(false); var ls_message = ''; var ls_logmessage = ''; if (xhr.status == 0) { ls_message = 'You are offline!!\n Please Check Your Network.'; } else if (xhr.status == 404) { ls_message = 'Requested URL not found.'; } else if (xhr.status == 500) { ls_message = 'Internal Server Error.';  } else if (thrownError == 'parsererror') { ls_message = 'Error.\nParsing JSON Request failed.' } else if (thrownError == 'timeout') { ls_message = 'Request Time out.'; } else { ls_message = 'Unknow Error.\n' + xhr.responseText; } $.messager.alert('&nbsp;',nl2br(ls_message),'error'); }, dataType: "html"
							});
						}},
						
						// ----- >> SP Button
					    { label: 'SP', icon: 'package_green', onclick: function() {
							var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								var ls_newvalue = prompt("Update ?",oSel.field1);
								
								setLoading(true);
								$.ajax({
									type: 'POST', url: gs_path+'/'+controller+'/ajax_store_procedure/?pk_master='+urlencode(oSel.pk_master)+'&as_newvalue='+urlencode(ls_newvalue), cache: false, data: jQuery.param( $('#fm_search').serializeArray().concat({ name:'sessid', value:sessid })),
									success: function(data) { setLoading(false); $("#datagrid").datagrid("reload"); if(data!=''){ $.messager.alert("Success",nl2br(data),"ok"); return false; } },
									error: function(xhr, ajaxOptions, thrownError) { setLoading(false); var ls_message = ''; var ls_logmessage = ''; if (xhr.status == 0) { ls_message = 'You are offline!!\n Please Check Your Network.'; } else if (xhr.status == 404) { ls_message = 'Requested URL not found.'; } else if (xhr.status == 500) { ls_message = 'Internal Server Error.';  } else if (thrownError == 'parsererror') { ls_message = 'Error.\nParsing JSON Request failed.' } else if (thrownError == 'timeout') { ls_message = 'Request Time out.'; } else { ls_message = 'Unknow Error.\n' + xhr.responseText; } $.messager.alert('&nbsp;',nl2br(ls_message),'error'); }, dataType: "html"
								});
							}
					    }} ];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
    });
//--><!]]></script>

    
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-blank-file" onclick="$('#fm_search').resetForm(); return false;">Reset</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>